package com.shaomengjie.meetingroom;

import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.ScaleAnimation;
import android.widget.TextView;

import com.shaomengjie.meetingroom.fragment.LeftFragment;
import com.shaomengjie.meetingroom.fragment.MiddleFragment;
import com.shaomengjie.meetingroom.fragment.RightFragment;

import java.util.ArrayList;
import java.util.List;

import me.majiajie.pagerbottomtabstrip.Controller;
import me.majiajie.pagerbottomtabstrip.PagerBottomTabLayout;
import me.majiajie.pagerbottomtabstrip.TabLayoutMode;
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectListener;

public class MainActivity2 extends AppCompatActivity {
    private PagerBottomTabLayout bottomTabLayout;
    private Controller controller;
    private List<Fragment> mFragmentList;
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initData();
        initView();
    }

    private void initData() {
        mFragmentList = new ArrayList<>();
        mFragmentList.add(new LeftFragment());
        mFragmentList.add(new MiddleFragment());
        mFragmentList.add(new RightFragment());
    }

    private void initView() {
        bottomTabLayout = (PagerBottomTabLayout) findViewById(R.id.tab);
        textView = (TextView) findViewById(R.id.toolbar_title);
        controller = bottomTabLayout.builder()
                .addTabItem(R.mipmap.ic_launcher,"第一个")
                .addTabItem(R.mipmap.ic_launcher,"第一个")
                .addTabItem(R.mipmap.ic_launcher,"第一个")
                .setMode(TabLayoutMode.CHANGE_BACKGROUND_COLOR)
                .build();
        controller.addTabItemClickListener(new OnTabItemSelectListener() {
            @Override
            public void onSelected(int index, Object tag) {
                int flag = 0;
                switch (index){
                    case 0:
                        flag = 0;
                        textView.setText("第一个");
                        break;
                    case 1:
                        flag = 1;
                        textView.setText("第二个");
                        break;
                    case 2:
                        flag = 2;
                        textView.setText("第三个");
                        break;
                }
                startAnimation();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.mainActivity_framelayout,mFragmentList.get(flag)).commit();
            }

            @Override
            public void onRepeatClick(int index, Object tag) {

            }
        });

        //controller.setDisplayOval(0,true);
    }

    private void startAnimation() {
        ObjectAnimator animator = new ObjectAnimator().ofFloat(textView,"Scale",1.2f);
        animator.setDuration(300);
        animator.start();
    }

}
